/**
 * 
 */
package com.sendMessage.demo.socket;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

import com.sendFile.demo.socket.ClientSocket;

/**
 * @author 周成瑜
 * 
 */
public class Client {

	private String ip = "192.168.253.105";// 设置成服务器IP

	private int port = 12345;

	public Client() {
		 try {
	            Socket socket = new Socket(ip, port); 
	            // 向服务器端发送数据 
	            OutputStream os =  socket.getOutputStream(); 
	            DataOutputStream bos = new DataOutputStream(os); 
	            bos.writeUTF("我是客户端，我向服务端发送你好！！"); 
	            bos.flush(); 

	            // 接收服务器端数据 
	            InputStream is = socket.getInputStream(); 
	            DataInputStream dis = new DataInputStream(is); 
	            System.out.println("客户端接收到服务端消息："+dis.readUTF()); 
	            
	            dis.close();
	            is.close();
	            bos.close();
	            os.close();
	            
	        } catch (UnknownHostException e) { 
	            e.printStackTrace(); 
	        } catch (IOException e) { 
	            e.printStackTrace(); 
	        } 
	}
	
	public static void main(String[] args) {
		new Client();
	}
	 
	
}
